package com.ada.spark.rddoperator

import org.apache.spark.{SparkConf, SparkContext}

/**
  * 作用：在类型为(K,V)和(K,W)的RDD上调用，返回一个相同key对应的所有元素对在一起的(K,(V,W))的RDD
  */
object Spark27_join {

    def main(args: Array[String]): Unit = {
        //创建SparkConf
        val conf = new SparkConf().setAppName("Spark27_join").setMaster("local[*]")
        //创建Spark上下文对象
        val sc = new SparkContext(conf)

        val rdd = sc.parallelize(Array((1, "a"), (2, "b"), (3, "c")))

        val rdd1 = sc.parallelize(Array((1, 4), (2, 5), (3, 6)))

        //在类型为(K,V)和(K,W)的RDD上调用，返回一个相同key对应的所有元素对在一起的(K,(V,W))的RDD
        val result = rdd.join(rdd1)

        println(result.collect().mkString(","))
        //(1,(a,4)),(2,(b,5)),(3,(c,6))
    }

}
